<!DOCTYPE html>
<html>
<div id="editForm">
  <div class="form-group">
    <label class="control-label col-xs-3 is-required">循环名称</label>
    <div class="col-xs-8">
      <div class="input-icon right">
        <input type="text" id="loop_name_txt" name="name" field="name" class="form-control" required/>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-xs-3">描述信息</label>
    <div class="col-xs-8">
      <div class="input-icon right">
        <input type="text" id="loop_desc_txt" name="desc" field="desc" class="form-control"/>
      </div>
    </div>
  </div>
  <div id="unpack_public_div">
    <div class="form-group">
      <label class="control-label col-xs-3 is-required" id="unpack_public_div_title">循环记录数</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" value="-1" required id="loop_count_txt" name="count" field="count"/>
        </div>
      </div>
    </div>
  </div>
  <div id="delim_loop_div">
    <div class="form-group">
      <label class="control-label col-xs-3 is-required">分隔符字符</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="loop_delimChar_txt" name="delimChar" field="delimChar" required/>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">需要转义的字符串</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="loop_escapeChar_txt" name="escapeChar" field="escapeChar"/>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">转义中文特殊字符</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <select id="loop_escapeZh_select" name="escapeZh" field="escapeZh" class="form-control select2">
            <option value="true">是</option>
            <option value="false">否</option>
          </select>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">转义字符</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="loop_escapePrefix_txt" value="\" name="escapePrefix" field="escapePrefix"/>
        </div>
      </div>
    </div>
  </div>

  <div id="xml_loop_div">
    <div class="form-group">
      <label class="control-label col-xs-3 is-required" id="xml_loop_div_title">xpath</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="loop_xpath_txt" name="xpath" field="xpath" required/>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">

  $(function () {
    //报文类型
    var nodeType = getPolicyType(pktSelectNode);
    //处理类型：解包unpack,解包：pack
    var processType = pktSelectNode.rootType;
	//初始化页面
	init(nodeType, processType);
    if (pktSelectNode.dataModel) {
      applyDrawing('#editForm', pktSelectNode.dataModel)
    }


  })

  //初始化
  function init(nodeType, processType) {
    /*$('#loop_count_txt').rules("add", {
      required: true,
      checkInput: true
    });*/
    hideAllDiv();
    if (processType == "pack") {
      hideAll("unpack_public_div");
      disabledAll("unpack_public_div");
    } else if (processType == "unpack") {
      enableAll("unpack_public_div");
      showAll("xml_struct_div");
    }

    if (nodeType == "delim") {
      hideAll("xml_loop_div");
      disabledAll("xml_loop_div");
      enableAll("delim_loop_div");
      showAll("delim_loop_div");
    } else if (nodeType == "cnaps2") {
      hideAll("delim_loop_div");
      disabledAll("delim_loop_div");
      enableAll("xml_loop_div");
      showAll("xml_loop_div");
      $("#unpack_public_div_title").removeClass('is-required')
      $("#xml_loop_div_title").html("xpath");
    } else if (nodeType == "xml") {
      hideAll("delim_loop_div");
      disabledAll("delim_loop_div");
      enableAll("xml_loop_div");
      showAll("xml_loop_div");
      $("#xml_loop_div_title").html("xpath");
      $("#unpack_public_div_title").html("循环记录数");
      $("#unpack_public_div_title").removeClass('is-required')
      $("#loop_count_txt").removeAttr("required");
      $("#loop_count_txt").rules("remove");
    } else if (nodeType == "json") {
      hideAll("delim_loop_div");
      disabledAll("delim_loop_div");
      enableAll("xml_loop_div");
      showAll("xml_loop_div");
      hideAll("unpack_public_div");
      disabledAll("unpack_public_div");
      $("#xml_loop_div_title").html("path");
    }
  }

  function hideAllDiv() {
    hideAll("delim_loop_div");
    hideAll("xml_loop_div");
  }


  //显示需要的元素div
  function showNeedDiv(type, processType) {
    if (type == "fixed") {
      if (processType == "unpack") {
        enableAll("unpack_public_div");
        $("#unpack_public_div").show();
      } else if (processType == "pack") {
        disabledAll("unpack_public_div");
        $("#unpack_public_div").hide();
      }
    }
  }
</script>
